package com.ruoyi.web.controller.report;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.groupCollectQuery.domain.GroupQueryT;
import com.ruoyi.groupCollectQuery.service.IHouseGroupCollectQueryTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 汇总(楼宇)
 * 
 * @author lijie
 * @date 2023-05-04
 */
@RestController
@RequestMapping("/report/groupCollectQuery")
public class HouseGroupCollectQueryTController extends BaseController {
    @Autowired
    private IHouseGroupCollectQueryTService houseGroupCollectQueryTService;

    /**
     * 查询资金汇总列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GroupQueryT groupQueryT) {
        startPage();
        List<GroupQueryT> list = houseGroupCollectQueryTService.selectHouseCollectGroupQueryTList(groupQueryT);
        if (list.size() != 0) {
            if (getDataTableSumJudge(list)) {
                GroupQueryT houseCollectQueryVO = houseGroupCollectQueryTService.selectHouseCollectGroupQuerySum(groupQueryT);
                houseCollectQueryVO.setAreaName("合计");
                list.add(houseCollectQueryVO);
            }
        }
        return getDataTable(list);
    }


    @Log(title = "楼宇资金汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/exportGroup")
    public void exportGroup(HttpServletResponse response, GroupQueryT groupQueryT) {
        List<GroupQueryT> list = houseGroupCollectQueryTService.selectHouseCollectGroupQueryTList(groupQueryT);
        if (getDataTableSumJudge(list)) {
            GroupQueryT houseCollectGroupQueryVO = houseGroupCollectQueryTService.selectHouseCollectGroupQuerySum(groupQueryT);
            houseCollectGroupQueryVO.setAreaName("合计");
            list.add(groupQueryT);
        }
        ExcelUtil<GroupQueryT> util = new ExcelUtil<GroupQueryT>(GroupQueryT.class);
        util.exportExcel(response, list, "楼宇资金汇总数据");


    }
}
